package com.bc.trade.vo;


import java.util.List;

import com.jfinal.kit.StrKit;

public class MessageFieldCheck {
	// 字段名
	private String fieldName;
	// 字段值
	private String fieldValue;
	// 是否必填
	private boolean isRequire;
	// 固定值
	private String fixedValue;
	
	/**
	 * 创建ValidationVO
	 * 
	 * @param fieldName
	 * @param fieldValue
	 * @param isRequire
	 * @param minLength
	 * @param maxLength
	 * @param fixedValue
	 * @return
	 */
	public MessageFieldCheck(String fieldName, String fieldValue, boolean isRequire, String fixedValue) {
		this.fieldName = fieldName;
		this.fieldValue = fieldValue;
		this.isRequire = isRequire;
		this.fixedValue = fixedValue;
	}
	
	public MessageFieldCheck(String fieldName, String fieldValue, boolean isRequire) {
		this.fieldName = fieldName;
		this.fieldValue = fieldValue;
		this.isRequire = isRequire;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getFieldValue() {
		return fieldValue;
	}

	public void setFieldValue(String fieldValue) {
		this.fieldValue = fieldValue;
	}

	public boolean isRequire() {
		return isRequire;
	}

	public void setRequire(boolean isRequire) {
		this.isRequire = isRequire;
	}

	
	public String getFixedValue() {
		return fixedValue;
	}

	public void setFixedValue(String fixedValue) {
		this.fixedValue = fixedValue;
	}
	
	/**
	 * 字段验证
	 * 
	 * @param validationList
	 * @return
	 */
	public static String check(List<MessageFieldCheck> ruleList) {
		StringBuffer sb = new StringBuffer();

		for (MessageFieldCheck rule : ruleList) {
			String name = rule.getFieldName();
			String value = rule.getFieldValue();

			// 必填
			if (rule.isRequire() && StrKit.isBlank(value)) {
				sb.append(name);
				sb.append("[必填] , ");
			}

			// 固定值验证
			if (StrKit.notBlank(rule.getFixedValue())) {
				if (rule.getFixedValue().equalsIgnoreCase(value) == false) {
					sb.append(name);
					sb.append("[不是指定值] , ");
				}
			}

		}
		return sb.toString();
	}

}
